package com.e.leandemo;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Context;
import android.os.Bundle;
import android.view.MotionEvent;
import android.view.View;
import android.widget.FrameLayout;
import android.widget.ListView;

import com.e.leandemo.adapters.AnimalAdapter;
import com.e.leandemo.model.Animal;
import com.e.leandemo.views.HeaderView;

import java.util.LinkedList;
import java.util.List;

public class IndexActivity extends AppCompatActivity {
    private List<Animal> data=null;
    private Context context;
    private AnimalAdapter animalAdapter=null;
    private ListView listView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_index);
        FrameLayout frameLayout =(FrameLayout) findViewById(R.id.frameLayout);
        final HeaderView headerView = new HeaderView(this);
        headerView.setOnTouchListener(new View.OnTouchListener() {
            @Override
            public boolean onTouch(View v, MotionEvent event) {
                headerView.bitmapX=event.getX();
                headerView.bitmapY=event.getY();
                headerView.invalidate();
                return true;
            }
        });
        frameLayout.addView(headerView);
        context=this;
        listView = (ListView)findViewById(R.id.animal_list);
        data = new LinkedList<>();
        data.add(new Animal("dog","dog say ",1));
        data.add(new Animal("cat","cat say ",1));
        data.add(new Animal("yu","yu say ",1));
        animalAdapter = new AnimalAdapter((LinkedList<Animal>)data,context);
        listView.setAdapter(animalAdapter);
    }
}